<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace model;
class Overzicht_Index{
    private $_bedrijven = array();
    public function getInfo(){
        $resultaat = array();
        //$_SESSION['bedrijven']=',GOOG,MSFT,NFLX';
        if(isset($_SESSION['bedrijven'])){
            $this->_bedrijven=  explode(',', $_SESSION['bedrijven']);
            //verwijderen eerste element van de array
            array_shift($this->_bedrijven);
            sort($this->_bedrijven);
            if(count($this->_bedrijven)>0){
                $url = 'http://finance.yahoo.com/d/quotes.csv/?s='.  implode(',',$this->_bedrijven).'&f=snl1d1t1cv';               $fileSize = 2000;
                $fHandle = fopen($url, 'r');
                $rawQuotaData = fread($fHandle, $fileSize);
                fclose($fHandle);
                var_dump($rawQuotaData);
                $rawQuotaData = preg_replace('/, /',' ', $rawQuotaData);
                $quotaData = explode("\n", $rawQuotaData);
                foreach ($quotaData as $quota) {
                    if(!empty($quota)){
                        $quota = str_getcsv($quota);
                        $tmp = array();
                        $tmp['symbool']=trim($quota[0],"\"");
                        $tmp['bedrijf']=trim($quota[1],"\"");
                        $tmp['koers']=trim($quota[2],"\"");
                        $tmp['tijdstip']=trim($quota[3],"\"")." ".trim($quota[4],"\"");
                        $percentage=trim($quota[5],"\"");
                        $percentage=  str_replace(' - ',' / ',$percentage);
                        $tmp['percentage']=$percentage;
                        $tmp['volume']=trim($quota[6],"\"");
                        array_push($resultaat, $tmp);
                    }
                    
                }
            }
        }
        return $resultaat;
    }
    
}

